//
//  HDCheckBData.m
//  OTIS_MD
//
//  Created by 何达达 on 2017/8/22.
//  Copyright © 2017年 hedada. All rights reserved.
//

#import "HDCheckBData.h"

@implementation HDCheckBData
+(BOOL)bdata1AttributeIsTrueOrFlase:(Bdata *)bdata{
    
    if ([self Current_infoAndUpAndDownCheck:bdata] == MDJSONBdataTypeDefult && [self LatchedCountAndCNT_DAndLastTSCheck:bdata] == MDJSONBdataTypeDefult) {
        return YES;
    }
    return NO;
}
+(BOOL)bdata2AttributeIsTrueOrFlase:(Bdata *)bdata
{
    if ([self BL_BSAndBD_BSAndBL_CRAndBD_CRCheck:bdata] == MDJSONBdataTypeDefult) {
        return YES;
    }
    return NO;
    
}
+(MDJSONBdataType)LatchedCountAndCNT_DAndLastTSCheck:(Bdata *)bdata{
    if ([self stringIsNum:bdata.LatchedCount]) {
        
    }else{
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self stringIsNum:bdata.CNT_D]) {
        
    }else{
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self stringIsNum:bdata.LastTS]) {
        
    }else{
        return MDJSONBdataTypeNotCompleted;
    }
    
        return MDJSONBdataTypeDefult;
}
//对Current_info和Up和Down的所有字段进行16进制进行检查
+(MDJSONBdataType)Current_infoAndUpAndDownCheck:(Bdata *)bdata{
    if ([self Runs_SRCheck:bdata.Current_info.Runs_SR] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    if ([self Runs_DCheck:bdata.Current_info.Runs_D] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BL_BSCheck:bdata.Current_info.BL_BS] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BD_BSCheck:bdata.Current_info.BD_BS] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BL_BCCheck:bdata.Current_info.BL_BC] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BD_BCCheck:bdata.Current_info.BD_BC] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self TUPCheck:bdata.Current_info.TUP] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self TDNCheck:bdata.Current_info.TDN] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    if ([self MinCheck:bdata.Up.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.Up.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.Up.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.Up.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.Up.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.Up.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    if ([self MinCheck:bdata.Down.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.Down.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.Down.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.Down.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.Down.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.Down.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
 
}

//对BL_BS和BD_BS和BL_CR和BD_CR的所有字段进行16进制进行检查
+(MDJSONBdataType)BL_BSAndBD_BSAndBL_CRAndBD_CRCheck:(Bdata *)bdata
{
    if ([self BL_BSPropertyCheck:bdata] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BD_BSPropertyCheck:bdata] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BL_CRPropertyCheck:bdata] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self BD_CRPropertyCheck:bdata] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
}
//对BL_BS所有字段进行16进制进行检查
+(MDJSONBdataType)BL_BSPropertyCheck:(Bdata *)bdata{
    if ([self MinCheck:bdata.BL_BS.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.BL_BS.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.BL_BS.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.BL_BS.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.BL_BS.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.BL_BS.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
}
//对BD_BS的所有字段进行16进制进行检查
+(MDJSONBdataType)BD_BSPropertyCheck:(Bdata *)bdata{
    if ([self MinCheck:bdata.BD_BS.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.BD_BS.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.BD_BS.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.BD_BS.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.BD_BS.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.BD_BS.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
}
//对BL_CR所有字段进行16进制进行检查
+(MDJSONBdataType)BL_CRPropertyCheck:(Bdata *)bdata{
    if ([self MinCheck:bdata.BL_CR.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.BL_CR.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.BL_CR.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.BL_CR.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.BL_CR.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.BL_CR.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
}
//对BD_CR的所有字段进行16进制进行检查
+(MDJSONBdataType)BD_CRPropertyCheck:(Bdata *)bdata{
    if ([self MinCheck:bdata.BD_CR.Min] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self MaxCheck:bdata.BD_CR.Max] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self AveCheck:bdata.BD_CR.Ave] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Min_RAMCheck:bdata.BD_CR.Min_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Max_RAMCheck:bdata.BD_CR.Max_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    
    if ([self Ave_RAMCheck:bdata.BD_CR.Ave_RAM] == MDJSONBdataTypeNotCompleted) {
        return MDJSONBdataTypeNotCompleted;
    }
    return MDJSONBdataTypeDefult;
}
//对Bdata里面的Current_info的Runs_SR进行十六进制检查
+(MDJSONBdataType)Runs_SRCheck:(NSString *)Runs_SR{
    if ([self hexadecimalCheck:Runs_SR]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的Runs_D进行十六进制检查
+(MDJSONBdataType)Runs_DCheck:(NSString *)Runs_D{
    if ([self hexadecimalCheck:Runs_D]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的BL_BS进行十六进制检查
+(MDJSONBdataType)BL_BSCheck:(NSString *)BL_BS{
    if ([self hexadecimalCheck:BL_BS]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的BD_BS进行十六进制检查
+(MDJSONBdataType)BD_BSCheck:(NSString *)BD_BS{
    if ([self hexadecimalCheck:BD_BS]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的BL_BC进行十六进制检查
+(MDJSONBdataType)BL_BCCheck:(NSString *)BL_BC{
    if ([self hexadecimalCheck:BL_BC]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的BD_BC进行十六进制检查
+(MDJSONBdataType)BD_BCCheck:(NSString *)BD_BC{
    if ([self hexadecimalCheck:BD_BC]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的TUP进行十六进制检查
+(MDJSONBdataType)TUPCheck:(NSString *)TUP{
    if ([self hexadecimalCheck:TUP]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的Current_info的TDN进行十六进制检查
+(MDJSONBdataType)TDNCheck:(NSString *)TDN{
    if ([self hexadecimalCheck:TDN]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}

//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Min进行16进制的检查
+(MDJSONBdataType)MinCheck:(NSString *)Min
{    if ([self hexadecimalCheck:Min]) {
        return MDJSONBdataTypeDefult;
     }
     return MDJSONBdataTypeNotCompleted;

}
//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Max进行16进制的检查
+(MDJSONBdataType)MaxCheck:(NSString *)Max
{    if ([self hexadecimalCheck:Max]) {
        return MDJSONBdataTypeDefult;
     }
    return MDJSONBdataTypeNotCompleted;
    
}
//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Ave进行16进制的检查
+(MDJSONBdataType)AveCheck:(NSString *)Ave
{   if ([self hexadecimalCheck:Ave]) {
        return MDJSONBdataTypeDefult;
     }
    return MDJSONBdataTypeNotCompleted;
    
}
//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Min_RAM进行16进制的检查
+(MDJSONBdataType)Min_RAMCheck:(NSString *)Min_RAM
{
    if ([self hexadecimalCheck:Min_RAM]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
    
}
//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Max_RAM进行16进制的检查
+(MDJSONBdataType)Max_RAMCheck:(NSString *)Max_RAM
{
    if ([self hexadecimalCheck:Max_RAM]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}
//对Bdata里面的BL_BS或BD_BS或BL_CR或BD_CR的Ave_RAM进行16进制的检查
+(MDJSONBdataType)Ave_RAMCheck:(NSString *)Ave_RAM
{
    if ([self hexadecimalCheck:Ave_RAM]) {
        return MDJSONBdataTypeDefult;
    }
    return MDJSONBdataTypeNotCompleted;
}

//正则表达式判断一个字符串是否是纯数字
+(BOOL)stringIsNum:(NSString *)string{
    NSString *regex = @"[0-9]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if ([pred evaluateWithObject:string]) {
        return YES;
    }
    return NO;
    
}


//通过正则表达式判断传入的字符串是不是十六进制
+(BOOL)hexadecimalCheck:(NSString *)string{
    
    NSString *regex = @"\b0[xX][0-9a-fA-F]+\b";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if ([pred evaluateWithObject:string]) {
        return YES;
    }
    return NO;
    
}
@end
